const { UUIDV4, UUID, STRING, INTEGER, TINYINT, DOUBLE, JSON, Model } = require('sequelize');
const db = require('../../helpers/db');
const { checkThePhone } = require('../../helpers/validator');
const AfterSale = require('./after-sale');

class OrderItem extends Model {}

OrderItem.init(
    {
        id: {
            type: UUID,
            defaultValue: UUIDV4,
            primaryKey: true,
            comment: '订单项 ID'
        },
        order: {
            type: STRING(24),
            comment: '订单编号'
        },
        goods: {
            type: UUID,
            unique: true,
            comment: '外键，商品ID'
        },
        sku: {
            type: JSON,
            unique: true,
            comment: '商品SKU详情'
        },
        price: {
            type: DOUBLE,
            comment: '商品数量',
            defaultValue: 0
        },
        postage: {
            type: DOUBLE,
            comment: '邮费',
            defaultValue: 0
        },
        count: {
            type: INTEGER,
            comment: '数量',
            defaultValue: 1
        }
    },
    {
        tableName: 'order_item',
        underscored: true,
        sequelize: db
    }
);

OrderItem.belongsTo(AfterSale, {
    foreignKey: 'orderItem'
});

module.exports = OrderItem;
